package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbEvent;
import com.ruoyi.system.service.ITbEventService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 事件记录Controller
 * 
 * @author ruoyi
 * @date 2025-07-16
 */
@RestController
@RequestMapping("/system/event")
public class TbEventController extends BaseController
{
    @Autowired
    private ITbEventService tbEventService;

    /**
     * 查询事件记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:event:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbEvent tbEvent)
    {
        startPage();
        List<TbEvent> list = tbEventService.selectTbEventList(tbEvent);
        return getDataTable(list);
    }

    /**
     * 导出事件记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:event:export')")
    @Log(title = "事件记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbEvent tbEvent)
    {
        List<TbEvent> list = tbEventService.selectTbEventList(tbEvent);
        ExcelUtil<TbEvent> util = new ExcelUtil<TbEvent>(TbEvent.class);
        util.exportExcel(response, list, "事件记录数据");
    }

    /**
     * 获取事件记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:event:query')")
    @GetMapping(value = "/{eventId}")
    public AjaxResult getInfo(@PathVariable("eventId") Long eventId)
    {
        return success(tbEventService.selectTbEventByEventId(eventId));
    }

    /**
     * 新增事件记录
     */
    @PreAuthorize("@ss.hasPermi('system:event:add')")
    @Log(title = "事件记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbEvent tbEvent)
    {
        return toAjax(tbEventService.insertTbEvent(tbEvent));
    }

    /**
     * 修改事件记录
     */
    @PreAuthorize("@ss.hasPermi('system:event:edit')")
    @Log(title = "事件记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbEvent tbEvent)
    {
        return toAjax(tbEventService.updateTbEvent(tbEvent));
    }

    /**
     * 删除事件记录
     */
    @PreAuthorize("@ss.hasPermi('system:event:remove')")
    @Log(title = "事件记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{eventIds}")
    public AjaxResult remove(@PathVariable Long[] eventIds)
    {
        return toAjax(tbEventService.deleteTbEventByEventIds(eventIds));
    }
}
